package Thread;
//应用:终止一个进程的语法来进行：在main()方法中控制这个进程的结束；
public class Demo11 {
    public static void main(String[] args) throws InterruptedException {
        Thread t=new Thread(()->{
            System.out.println(Thread.currentThread().getName());
            //在那个进程中进行调用该线程就会返回这个线程的名字；
            while(!Thread.currentThread().isInterrupted()){
                System.out.println("hello thread");
                try{
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    //throw new RuntimeException(e);
                    break;
                }
            }
            System.out.println("thread线程已经被终止了");
        });
        t.start();
        Thread.sleep(3000);
        t.interrupt();//将调用此方法的线程终止；
        System.out.println("main线程正在尝试终止该线程");
        System.out.println(Thread.currentThread().getName());
    }
}
